main()
{
	doortriggers = getentarray("doortrig","targetname");
	for(i=0;i<doortriggers.size;i++)
	{
		doortriggers[i] thread door_think();
	}
}

door_think()
{
	self.doormoving = false;
	self.doorclosed = true;
	self.doormodel = getent(self.target, "targetname");

	self enablelinkto();
	self linkto(self.doormodel);

	while (1)
	{
		self waittill("trigger");
		if(!self.doormoving)
		self thread door_move();
	}
}

door_move()
{
	self.doormoving = true;
	if(self.doorclosed)
	{
		self.doormodel rotateyaw(-90,1,0.5,0.5);
		self.doormodel waittill("rotatedone");
		self.doorclosed = false;
	}
	else
	{
		self.doormodel rotateyaw(90,1,0.5,0.5);
		self.doormodel waittill("rotatedone");
		self.doorclosed = true;
	}
	self.doormoving = false;
} 